package cn.hsa.fqz.handler;

import cn.hsa.fqz.listener.UserOperateEvent;
import cn.hsa.hsaf.auth.security.utils.SpringContextUtils;
import cn.hsa.hsaf.core.framework.context.HsafContextHolder;
import cn.hsa.hsaf.core.framework.util.CurrentUser;
import cn.hsa.hsaf.core.framework.web.HsafRequestMappingHandlerAdapter;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author luoze
 * @date 2023/5/21 9:24 下午
 */
public class CustomRequestMappingHandlerAdapter extends HsafRequestMappingHandlerAdapter {


    @Autowired
    private ApplicationEventPublisher publisher;

    @Override
    protected boolean supportsInternal(HandlerMethod handlerMethod) {
        CurrentUser currentUser = HsafContextHolder.getContext().getCurrentUser();
        UserOperateEvent event = new UserOperateEvent(currentUser);
        publisher.publishEvent(event);
        return super.supportsInternal(handlerMethod);
    }

    @Override
    protected ModelAndView handleInternal(HttpServletRequest request, HttpServletResponse response, HandlerMethod handlerMethod) throws Exception {

        return super.handleInternal(request, response, handlerMethod);
    }

}
